namespace Microsoft.VisualStudio.EnterpriseTools.OperationDesigner
{
    using Microsoft.VisualStudio.Modeling;
    using Microsoft.VisualStudio.VirtualTreeGrid;
    using System;
    using System.ComponentModel;
    using System.Windows.Forms;

    public abstract class ColumnDescriptor : PropertyDescriptor, IDisposable
    {
        public const int CalculatePercentage = -1;
        private IOperationDesignerColumnHost host;
        private float initialPercentage;

        protected ColumnDescriptor(string name) : this(name, -1f)
        {
        }

        protected ColumnDescriptor(string name, float initialPercentage) : base(name, null)
        {
            this.initialPercentage = initialPercentage;
        }

        public virtual void AddEventHandlers(Store store)
        {
        }

        public virtual bool AllowKeyDownProcessing(KeyEventArgs e)
        {
            return true;
        }

        public virtual bool AllowKeyPressProcessing(char key, Keys modifiers)
        {
            return true;
        }

        public override bool CanResetValue(object component)
        {
            return false;
        }

        protected virtual void Dispose(bool disposing)
        {
        }

        ~ColumnDescriptor()
        {
            this.Dispose(false);
        }

        public virtual string GetCheckBoxTransactionName(object component)
        {
            return string.Empty;
        }

        public virtual CheckBoxState GetCheckBoxValue(object component)
        {
            throw new NotImplementedException("GetCheckBoxValue");
        }

        public virtual object GetInPlaceEdit(object component, ref string alternateText)
        {
            TypeEditorHost host = OperationDesignerTreeControl.CreateTypeEditorHost(this, component);
            if (host != null)
            {
                host.DismissLabelEditOnDropDownClose = true;
                return host;
            }
            return typeof(OperationDesignerInPlaceEdit);
        }

        public virtual string GetTipText(object component)
        {
            return null;
        }

        public virtual OperationDesignerValueSupportedStates GetValueSupported(object component)
        {
            return OperationDesignerValueSupportedStates.Supported;
        }

        public virtual void RemoveEventHandlers(Store store)
        {
        }

        public override void ResetValue(object component)
        {
        }

        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }

        void IDisposable.Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        public virtual StateRefreshChanges ToggleCheckBoxValue(object component)
        {
            throw new NotImplementedException("ToggleCheckBoxValue");
        }

        public virtual bool ColumnIsCheckBox
        {
            get
            {
                return false;
            }
        }

        public override System.Type ComponentType
        {
            get
            {
                return typeof(ModelElement);
            }
        }

        public IOperationDesignerColumnHost Host
        {
            get
            {
                return this.host;
            }
            set
            {
                this.host = value;
            }
        }

        public float InitialPercentage
        {
            get
            {
                return this.initialPercentage;
            }
            set
            {
                this.initialPercentage = value;
            }
        }

        public override bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public override System.Type PropertyType
        {
            get
            {
                return typeof(string);
            }
        }
    }
}

